package frame.options.simulation.create.rounding;

import java.util.List;

import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import model.algorithms.rounding.RoundingAlgorithm;

import com.nexes.wizard.WizardPanelDescriptor;

import frame.options.simulation.create.CreateSimulationWizard;
import frame.options.simulation.create.embedding.EmbeddingDescriptor;
import frame.options.simulation.create.linksMapping.LinksMappingDescriptor;

public class RoundingDescriptor extends WizardPanelDescriptor implements ListSelectionListener
{
	public static final String IDENTIFIER = "RoundingDescriptor";
	
	private RoundingPanel roundingPanel;
	public RoundingPanel getRoundingPanel(){ return this.roundingPanel; }
	public void setRoundingPanel( RoundingPanel roundingPanel ){ this.roundingPanel = roundingPanel; }
	
	public RoundingDescriptor( List< RoundingAlgorithm > roundingAlgorithms )
    {
    	this.setRoundingPanel( new RoundingPanel( roundingAlgorithms ) );
		this.getRoundingPanel().addListeners( this );
		
		this.setPanelDescriptorIdentifier( RoundingDescriptor.IDENTIFIER );
		this.setPanelComponent( this.getRoundingPanel() );
    }
	
	@Override
	public Object getBackPanelDescriptor()
	{
		return EmbeddingDescriptor.IDENTIFIER;
	}
	
    @Override
	public Object getNextPanelDescriptor()
    {
    	return LinksMappingDescriptor.IDENTIFIER;
    }
    
    @Override
	public void aboutToDisplayPanel()
    {
    	this.getWizard().setNextFinishButtonEnabled( false );
    }
	
	@Override
	public void valueChanged( ListSelectionEvent listSelectionEvent )
	{
    	if( this.getRoundingPanel().getRoundingAlgorithmsList().getSelectedValuesList().size() == 1 )
    	{
    		( (CreateSimulationWizard) this.getWizard() ).setRoundingAlgorithm( this.getRoundingPanel().getSelectedRoundingAlgorithm() );
    		this.getWizard().setNextFinishButtonEnabled( true );
    	}
    	else
    		this.getWizard().setNextFinishButtonEnabled( false );
	}

}
